package network.UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author zxl
 * @version 1.0
 * @date 2021/10/22 10:44
 */
public class Server {
    public static void main(String[] args) throws Exception {
        //开放端口
        DatagramSocket socket = new DatagramSocket(9002);
        //接收数据包
        byte[] bytes = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bytes, 0, bytes.length);
        //阻塞接收
        socket.receive(datagramPacket);
        byte[] data = datagramPacket.getData();
        System.out.println(new String(data,0, data.length));
        //关闭连接
        socket.close();
    }
}
